package route

import (
	controllers "05demo-gin-gorm-swagger/controller"
	doc "05demo-gin-gorm-swagger/docs"
	"github.com/gin-gonic/gin"
	ginSwaggerfiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

func InitRouter() *gin.Engine {
	router := gin.Default()

	//测试-controller
	router.GET("/user/list", controllers.ListTest)
	router.POST("/user/create", controllers.CreateTest)
	router.POST("/user/update", controllers.UpdateTest)
	router.POST("/user/delete", controllers.DeleteTest)
	// 注册swagger
	registerSwagger(router)
	return router
}

func registerSwagger(r gin.IRouter) {
	// API文档访问地址: http://host/swagger/index.html
	// 注解定义可参考 https://github.com/swaggo/swag#declarative-comments-format
	// 样例 https://github.com/swaggo/swag/blob/master/example/basic/api/api.go
	doc.SwaggerInfo.BasePath = "/"
	doc.SwaggerInfo.Title = "管理后台接口"
	doc.SwaggerInfo.Description = "实现一个管理系统的后端API服务"
	doc.SwaggerInfo.Version = "1.0"
	doc.SwaggerInfo.Host = "localhost:8080"
	doc.SwaggerInfo.Schemes = []string{"http", "https"}
	r.GET("/swagger/*any", ginSwagger.WrapHandler(ginSwaggerfiles.Handler))
}
